package cn.edu.java.io.outputstream.filteroutputstream;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class BufferedOutputStreamDemo {
    public static void main(String[] args) {
        String filename = "output/example.txt";
        String data = "Hello, World!";

        try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filename))) {
            byte[] bytes = data.getBytes(); // 将字符串转换为字节数组
            bos.write(bytes); // 将字节数组写入到缓冲输出流的缓冲区中，在调用 flush() 或者 close() 方法时对数据进行写入
            System.out.println("Data has been written to the file.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

